// subpackage/pay/index.js
var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../components/base/m-button/index"),
  o = require("../../../config/index"),
  s = require("../../../utils/index"),
  d = s.helper.publish;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bankAccount: '',
    bankCode: '',
    bankNo: '',
    id: '',
    balance: 0,
    amount: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getBalance()
  },
  allWithdraw() {
    this.setData({
      amount: this.data.balance
    })
  },
  getBalance() {
    wx.showLoading({
      title: '加载中...',
    })
    $.request['GET/business/wechat/account/detail']().then(res => {
      res = res[0]
      if (res.code === 20002) {
        this.setData({
          balance: res.data.balance
        })
      } else {
        $.msg(res.msg)
      }
    }).finally(() => {
      wx.hideLoading()
    })
  },
  chooseBank() {
    wx.navigateTo({
      url: '/subpackage/personal/integral/bank/index?type=1',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },
  onSubmit: (0, a.apply)(i(r().mark((function e() {
    var t, i, a, o, s, u, c, l, p, f, m, h, b;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          if (!this.data.amount) {
            wx.showToast({
              icon: "none",
              title: '请输入提现金额',
            })
            return e.next = 15
          } else if (this.data.amount < 0.1) {
            wx.showToast({
              icon: "none",
              title: '提现金额不能低于0.1元',
            })
            return e.next = 15
          } else {
            return e.next = 2
          }


          case 2:
            return e.next = 15, $.request['POST/business/wechat/account/withdraw/apply']({
              amountStr: this.data.amount,
              type: 1
            }).then(res => {
              res = res[0]
              if (res.code == 20002) {
                wx.showToast({
                  icon: "none",
                  title: '提现成功',
                })
                setTimeout(() => {
                  wx.navigateBack()
                }, 500);
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                })
              }
            });
          case 5:
            if (a = e.sent, a.detail && !((null === (t = a.detail) || void 0 === t ? void 0 : t.length) < 5)) {
              e.next = 7;
              break
            }
            return e.abrupt("return", void $.msg("招工详情必须大于5个字符"));
          case 7:
            if (o = a.address, s = a.type, u = this.data, c = u.userInfo, l = u.machineConfig, p = u.uu_id, f = u.mode, m = n(n({
                mode: f,
                user_name: c.name
              }, o), {}, {
                class_id: (null == s || null === (i = s.map((function (e) {
                  return e.id
                }))) || void 0 === i ? void 0 : i.join(",")) || "",
                modelId: (null == s || null === (i = s.map((function (e) {
                  return e.id
                }))) || void 0 === i ? void 0 : i.join(",")) || "",
                modelName: (null == s || null === (i = s.map((function (e) {
                  return e.name
                }))) || void 0 === i ? void 0 : i.join(",")) || "",
                phone: a.tel || "",
                description: a.detail || "",
                place: o.address,
                provinceId: o.province_id,
                provinceText: o.province_text,
                cityId: o.city_id,
                cityText: o.city_text,
              }), !p) {
              e.next = 13;
              break
            }
            b = {
              mode: f,
              user: c.name,
              modelId: (null == s || null === (i = s.map((function (e) {
                return e.id
              }))) || void 0 === i ? void 0 : i.join(",")) || "",
              modelName: (null == s || null === (i = s.map((function (e) {
                return e.name
              }))) || void 0 === i ? void 0 : i.join(",")) || "",
              phon: a.tel || "",
              capt: a.code || "",
              desc: a.detail || "",
              title: a.detail || "",
              type: (null == s || null === (h = s.map((function (e) {
                return e.id
              }))) || void 0 === h ? void 0 : h.join(",")) || "",
              longitude: o.longitude,
              latitude: o.latitude,
              place: o.address,
              id: p
            }, d.sendMachineInfo(m, p), e.next = 15;
            break;
          case 13:
            return e.next = 15, d.checkPayReleasePopup(f, (function (e) {
              e ? (m.pay_code = "10001", m.coin = l.push_consume_coin, d.sendMachineInfo(m)) : d.sendMachineInfo(m)
            }));
          case 15:
          case "end":
            return e.stop()
      }
    }), e, this)
  })))),
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})